#!/bin/bash
# 清理现有进程
echo "停止现有服务..."
pkill -f "python manage.py runserver" 2>/dev/null
sleep 2

# 清理日志
echo "清理日志..."
rm -f /tmp/mes_clean_*.log

# 启动服务
echo "启动MES系统..."
echo "时间: $(date)"

# 启动三个服务
echo "启动基础MES服务 (端口8001)..."
nohup python manage.py runserver 0.0.0.0:8001 --settings=settings_clean > /tmp/mes_clean_8001.log 2>&1 &
echo "基础MES服务启动完成，PID: $!"

echo "启动完整MES服务 (端口8002)..."
nohup python manage.py runserver 0.0.0.0:8002 --settings=settings_clean > /tmp/mes_clean_8002.log 2>&1 &
echo "完整MES服务启动完成，PID: $!"

echo "启动管理后台服务 (端口8003)..."
nohup python manage.py runserver 0.0.0.0:8003 --settings=settings_clean > /tmp/mes_clean_8003.log 2>&1 &
echo "管理后台服务启动完成，PID: $!"

# 等待服务启动
echo "等待服务启动..."
sleep 8

# 检查服务状态
echo "检查服务状态..."
ps aux | grep "python manage.py runserver" | grep -v grep

echo ""
echo "=== MES系统启动完成 ==="
echo "基础MES服务: http://175.27.138.86:8001/admin/"
echo "完整MES服务: http://175.27.138.86:8002/admin/"
echo "管理后台: http://175.27.138.86:8003/admin/"
echo ""
echo "管理员账户:"
echo "用户名: admin"
echo "密码: admin123"
echo ""
echo "查看日志:"
echo "tail -f /tmp/mes_clean_8001.log"
echo "tail -f /tmp/mes_clean_8002.log"
echo "tail -f /tmp/mes_clean_8003.log"
echo ""
echo "停止服务:"
echo "pkill -f 'python manage.py runserver'" 